package com.hl.controller.shangpin;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.hl.domain.ProductPlatform;
import com.hl.service.IProductPlatformService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 平台商品Controller
 *
 * @author ruoyi
 * @date 2025-08-07
 */
@RestController
@RequestMapping("/platform")
public class ProductPlatformController extends BaseController
{
    @Autowired
//    @Qualifier("productPlatformServiceImpl")
    private IProductPlatformService productPlatformService;

    /**
     * 查询平台商品列表
     */
//    @RequiresPermissions("shangpin:platform:list")
    @GetMapping("/list")
    public TableDataInfo list(ProductPlatform productPlatform)
    {
        startPage();
        List<ProductPlatform> list = productPlatformService.selectProductPlatformList(productPlatform);
        return getDataTable(list);
    }

    /**
     * 导出平台商品列表
     */
    @RequiresPermissions("shangpin:platform:export")
    @Log(title = "平台商品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProductPlatform productPlatform)
    {
        List<ProductPlatform> list = productPlatformService.selectProductPlatformList(productPlatform);
        ExcelUtil<ProductPlatform> util = new ExcelUtil<ProductPlatform>(ProductPlatform.class);
        util.exportExcel(response, list, "平台商品数据");
    }

    /**
     * 获取平台商品详细信息
     */
    @RequiresPermissions("shangpin:platform:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(productPlatformService.selectProductPlatformById(id));
    }
    /**
     * 获取前端平台商品详细信息
     */
//    @RequiresPermissions("shangpin:platform:query")
    @GetMapping(value = "/front/{id}")
    public AjaxResult getInfo1(@PathVariable("id") Integer id)
    {
        return success(productPlatformService.selectProductPlatformById(id));
    }
    /**
     * 新增平台商品
     */
    @RequiresPermissions("shangpin:platform:add")
    @Log(title = "平台商品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductPlatform productPlatform)
    {
        return toAjax(productPlatformService.insertProductPlatform(productPlatform));
    }

    /**
     * 修改平台商品
     */
    @RequiresPermissions("shangpin:platform:edit")
    @Log(title = "平台商品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductPlatform productPlatform)
    {
        return toAjax(productPlatformService.updateProductPlatform(productPlatform));
    }

    /**
     * 删除平台商品
     */
    @RequiresPermissions("shangpin:platform:remove")
    @Log(title = "平台商品", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(productPlatformService.deleteProductPlatformByIds(ids));
    }

    /**
     * 上架商品
     */
    @RequiresPermissions("shangpin:platform:edit")
    @Log(title = "上架商品", businessType = BusinessType.UPDATE)
    @PutMapping("/list/{id}")
    public AjaxResult list(@PathVariable("id") Integer id)
    {
        ProductPlatform productPlatform = new ProductPlatform();
        productPlatform.setId(id);
        productPlatform.setStatus(1);
        return toAjax(productPlatformService.updateProductPlatform(productPlatform));
    }

    /**
     * 下架商品
     */
    @RequiresPermissions("shangpin:platform:edit")
    @Log(title = "下架商品", businessType = BusinessType.UPDATE)
    @PutMapping("/delist/{id}")
    public AjaxResult delist(@PathVariable("id") Integer id)
    {
        ProductPlatform productPlatform = new ProductPlatform();
        productPlatform.setId(id);
        productPlatform.setStatus(0);
        return toAjax(productPlatformService.updateProductPlatform(productPlatform));
    }

    /**
     * 获取销售模式选项
     */
    @GetMapping("/salesModelOptions")
    public AjaxResult getSalesModelOptions()
    {
        // 返回销售模式选项
        return success(new Object[][]{
            {"retail", "零售"},
            {"wholesale", "批发"},
            {"direct", "直销"},
            {"agency", "代理"}
        });
    }
}
